﻿window.$jscript.fn.wangeditor = (function () {
    var __FN = function () {
        return new __FN.fn._init();
    };
    var hxt = window.$jscript.fn;
    __FN.fn = __FN.prototype = {
        _init: function () { return this; },
        param: { msg: '', link: '' },
        ready: function (options) {
            var self = this;
            $.each(options, function (idx, item) {
                if (self.param.hasOwnProperty(idx)) {
                    self.param[idx] = item;
                }
            });
            hxt.config.link = self.param.link;
            self.initPage();
        },
        initPage: function () {
            var self = this;
            hxt.element.elVue = new Vue({
                data: function () {
                    var _this = this;
                    return {
                        msgInfo: JSON.parse(hxt.fromBase64(self.param.msg)) || {},
                        wangEditor : null,
                    };
                },

                computed: {

                },
                mounted: function () {
                    var _this = this;
                    _this.wangEditor = window.wangEditor;
                    const editorConfig = {
                        readOnly: true,
                        placeholder: 'Type here...',
                        onChange(editor) {
                            const html = editor.getHtml()
                            //console.log('editor content', html)
                            // 也可以同步到 <textarea>
                            _this.html = html;
                        }
                    };
                    const editor = _this.wangEditor.createEditor({
                        selector: '#editor-container',
                        html: _this.msgInfo.html,
                        config: editorConfig,
                        mode: 'default', // or 'simple'
                    });
                },
                methods: {

                },
                components: {
                }
            }).$mount('#app');
        }
    };
    __FN.fn._init.prototype = __FN.fn;
    return __FN.fn;
})();